package com.example.userregister;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.userregister.bean.WeaponInfo;

public class ShopActivity extends AppCompatActivity {
    WeaponInfo weaponInfo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shop);
        //1-初始化武器文本框的值
        weaponInfo =new WeaponInfo(20,100,30);
        TextView tvWeapon = (TextView) findViewById(R.id.tv_shop_weapon);
        tvWeapon.setText("生命值：+"+weaponInfo.getLife());
        tvWeapon.append("\n攻击力：+"+weaponInfo.getAttack());
        tvWeapon.append("\n敏捷度：+"+weaponInfo.getSpeed());
        //2-返回详情页，带回这个武器的属性值
        LinearLayout llWeanponItem = (LinearLayout) findViewById(R.id.ll_weaponitem);
        llWeanponItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //将数据带回
                Intent intent = new Intent();
                //对象的序列化，将对象的属性转换成byte[],之后进行传输
                intent.putExtra("weapon",weaponInfo);
                setResult(2,intent);
                finish();
            }
        });

    }
}
